//
//  PhotoStackViewController.h
//  Memento 2.0
//
//  Created by Matt Toth on 10-07-05.
//  Copyright 2010 Team Memento. All rights reserved.
//
//  Portions adapted from SpeakHereController.h; see http://developer.apple.com/iphone/library/samplecode/SpeakHere/Listings/Classes_SpeakHereController_mm.html#//apple_ref/doc/uid/DTS40007802-Classes_SpeakHereController_mm-DontLinkElementID_20
//
//  Description: This class is the main view controller in Memento.  It handles all user interaction, including photo taking,
//  audio recording, and browsing through the photo collection.  In this version, it is the sole view controller, but future versions
//  may introduce a separate view controller for the "Memory Browser" mode, which has different and expanded functionality.
//
//  10-07-31: Add settings panel (C. Maddocks)
//  10-07-30: Add outlets to support disabling of playback/camera buttons when recording  (C. Maddocks)
//  10-07-30: Swap direction of memories, so that left-most image is most recent / nearest  (C. Maddocks)
//  10-07-30: Refactor code in viewDidLoad: to help resolve low-memory view reinitialization issue  (C. Maddocks)
//  10-07-26: Add IBActions for moveFirst: and moveLast:  (C. Maddocks)
//  10-07-21: Bump version in header to 2.0.  (C. Maddocks)

#import <Foundation/Foundation.h>
#import "AQLevelMeter.h"
#import "AQPlayer.h"
#import "AQRecorder.h"
#import "PhotoCollection.h"
#import "Memory.h"
#import "MemorySaveOperation.h"

// Tolerance levels for swipe detection
#define kMinimumGestureLength           20
#define kMaximumVariance                15

//for shaking code
#define kAccelerationThreshold        2.2
#define kUpdateInterval               (1.0f/10.0f)

@class InfoViewController;

@interface PhotoStackViewController : UIViewController < UIImagePickerControllerDelegate, UINavigationControllerDelegate, CLLocationManagerDelegate, UIAccelerometerDelegate, UIAlertViewDelegate > {

	// Memory-related UI elements
	IBOutlet UIView				*memoryView;
	IBOutlet UIView				*settingsView;
	
	IBOutlet UIImageView		*imageView;
	IBOutlet UILabel			*dateLabel;
	IBOutlet UILabel			*timeLabel; 
	IBOutlet UILabel			*locationLabel;
	
	// Browsing-related UI elements
	IBOutlet UIButton			*btnLeft;
	IBOutlet UIButton			*btnLeftmost;
	IBOutlet UIButton			*btnRight;
	IBOutlet UIButton			*btnRightmost;
	
	// Recording-related UI elements
//	IBOutlet UIToolbar			*toolbar;
	IBOutlet UIButton	        *btn_record;
	IBOutlet UIButton	        *btn_play;
	IBOutlet UIButton	        *btn_photo;
	IBOutlet UILabel			*fileDescription;
	IBOutlet AQLevelMeter		*lvlMeter_in;

	// Recording-related support functions and data structures
	AQPlayer*					player;
	AQRecorder*					recorder;
	BOOL						playbackWasInterrupted;
	BOOL						playbackWasPaused;
	CFStringRef					recordFilePath;	
	
	// Touch handling
	CGPoint gestureStartPoint;
	BOOL swipeHandled;
	
	// Shake handling
	BOOL shakeHandled;
	
	// Primary data collection
	PhotoCollection*			photoCollection;
	
	// Test
	IBOutlet UIButton			*testButton;
	
	// Concurrency
	NSOperationQueue			*imageSaveQueue;
	
	//for GPS
	CLLocationManager           *locationManager;
	CLLocation                  *startingPoint;
	int							sortMethod;
}

@property (nonatomic, retain)   PhotoCollection     *photoCollection;

@property (nonatomic, retain)   UIImageView         *imageView;
//@property (nonatomic, retain)	UIToolbar			*toolbar;
@property (nonatomic, retain)	UIButton		    *btn_record;
@property (nonatomic, retain)	UIButton		    *btn_play;
@property (nonatomic, retain)   UIButton		    *btn_photo;
@property (nonatomic, retain)	UILabel				*fileDescription;
@property (nonatomic, retain)	AQLevelMeter		*lvlMeter_in;

@property (readonly)			AQPlayer			*player;
@property (readonly)			AQRecorder			*recorder;
@property						BOOL				playbackWasInterrupted;

@property (nonatomic, retain)	UIButton			*testButton;

//for GPS
@property (retain, nonatomic)   CLLocationManager   *locationManager;
@property (retain, nonatomic)   CLLocation *startingPoint;
@property (assign, nonatomic)	int sortMethod;

- (IBAction)record: (id) sender;	
- (IBAction)play: (id) sender;		
- (IBAction)photo: (id) sender;

- (IBAction)setupTestData;			// Generates test data in the PhotoCollection for manual testing.  To be removed in final build.
- (IBAction)hideTestButton;			// Hides the test button so that app looks as a regular user would see it.

- (IBAction)moveLeft;				// "next" in this view means "more recent".  By default Memento loads the most recent (i.e., last) memory.
- (IBAction)moveRight;
- (IBAction)moveLeftmost;
- (IBAction)moveRightmost;
- (IBAction)toggleSettings;			// show/hide settings panel

- (void)loadAudioQueue;

- (void)saveData;
- (void)loadData;

- (void)glassifyButtons;
- (void)resetDisplay;

- (void)loadTutorial;
- (void)loadTutorialMemory:(NSString *)imageName;
	
@end
